Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.os.uefi.protocol: ziggify function signatures #23214

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dotcarmen
Copy link
Contributor

@dotcarmen dotcarmen commented Mar 12, 2025

A lot of the function signatures in std.os.uefi.protocol aren't very ziggy. This PR modifies a significant number of the namespace's functions to align more with verbose Zig code.

  • Some parameters changed from * to *const and vice-versa as appropriate
  • Some pairs of parameters that represent slices were consolidated into a single slice parameter
  • Status errors associated with each function according to the UEFI Specification are handled specifically, resulting in narrow error unions being returned from each function
    • unexpected status codes result in a new call to uefi.unexpectedError, which is akin to posix.unexpectedError
  • As appropriate, return values from various functions are returned directly when the underlying function's return value is .success, rather than requiring an output pointer parameter

note: most of std.os.uefi is untested, and that's not really changing here. I'm mostly focused on making sure there are no compiler errors. Any further problems will require a future PR to address.

@dotcarmen
Copy link
Contributor Author

one problem I'm struggling to address in this PR is the potential for the underlying API to return status codes - most of std.os.uefi already assumes non-.success return values are errors, but I wonder if warnings (high bit clear) should be stored somewhere?

@dotcarmen dotcarmen force-pushed the uefi-fn-signatures branch from c5ad247 to 3c4cfa8 Compare March 12, 2025 15:39
@dotcarmen dotcarmen force-pushed the uefi-fn-signatures branch from 3c4cfa8 to 29c91b7 Compare March 13, 2025 15:42
pub fn delete(self: *File) bool {
switch (self._delete(self)) {
.success => return true,
.warn_delete_failure => return false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a good solution. Once we find an API that can return both a value and a warning it'll get awkward though.

}

/// Polls for incoming data packets and processes outgoing data packets.
pub fn poll(self: *const Ip6) Status {
return self._poll(self);
pub fn poll(self: *Ip6) PollError!void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this should return PollError!bool, where .success is true and .not_ready is false - wdyt? according to the spec, poll returns .not_ready when no data is processed, as opposed to .success when data is processed

Comment on lines +44 to +46
data_type: DataType,
data_size: usize,
data: *const anyopaque,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the data type should probably be a union (enum) eventually, but i'm concerned about how that would affect getData where the out pointer is the field defined by data_type from the union

pub const CreateChildError = uefi.UnexpectedError || error{
InvalidParameter,
OutOfResources,
} || Error; // TODO: according to the spec, _any other_ status is returnable?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i only did a little bit of google, but couldn't figure out what Other means in the spec. i have a feeling it's referring to warnings, but i'm wary of assuming such and i think i'd rather let somebody who encounters this file their own bug report/pr to fix...

Comment on lines +91 to +97
// .invalid_parameter => return Error.InvalidParameter,
// .unsupported => return Error.Unsupported,
// .not_started => return Error.NotStarted,
else => |status| {
try status.err();
// TODO: only warnings get here I think?
return uefi.unexpectedStatus(status);
Copy link
Contributor Author

@dotcarmen dotcarmen Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on how we decide on approaching Other above, i'll change the logic here and below

@dotcarmen
Copy link
Contributor Author

for warnings, i'm considering a global pub var warning: Status = .success; in uefi.zig, which the user can check for a value. then, uefi.unexpectedStatus can return UnexpectedError!void and callers can return .success value.

alternatively, I can make a pub fn MaybeWarned(T: type) type which has an optional warning: ?Status field in addition to result: T. thoughts?

Comment on lines +38 to +39
if (size_of_info != @sizeOf(Mode.Info))
return error.Unexpected
Copy link
Contributor Author

@dotcarmen dotcarmen Mar 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also thoughts on this pattern? the 3rd parameter is for informing the caller of the implementation's sizeOf(Mode.Info) even though the struct is well-defined according to the spec...

this also applies to SimpleNetwork.statistics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants